/**
 * 
 */
package com.somobile.json;

import java.util.Date;
import java.util.Map;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.somobile.json.converters.DateTimeDeserializer;


/**
 * @author JatanP
 *
 */
public class GSONHelper
{
	private GSONHelper()
	{
		
	}
	
	public static Gson getGson()
	{
		GsonBuilder gb = getDefaultGsonBuilder();
		return gb.create();
	}
	
	public static Gson getGson(Map<Class,JsonDeserializer> typeAdapters)
	{
		GsonBuilder gb = getDefaultGsonBuilder();
		
		for(Class key : typeAdapters.keySet())
		{
			gb.registerTypeAdapter(key, typeAdapters.get(key));
		}	
		
		return gb.create();
	}

	private static GsonBuilder getDefaultGsonBuilder()
	{
		GsonBuilder gb = new GsonBuilder();
		gb.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
		gb.registerTypeAdapter(Date.class, DateTimeDeserializer.getInstance());
		return gb;
	}

}
